package com.molichuxing.gateway.bff.dealer.services.impl;

import com.molichuxing.framework.exception.BizException;
import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.gateway.bff.dealer.convertor.Convert;
import com.molichuxing.gateway.bff.dealer.entity.response.DeviceInfoVo;
import com.molichuxing.gateway.bff.dealer.entity.response.DeviceUnionpayParamVo;
import com.molichuxing.gateway.bff.dealer.services.DeviceBffService;
import com.molichuxing.services.business.dto.response.DeviceInfoBizDto;
import com.molichuxing.services.business.service.DeviceBizService;
import com.molichuxing.services.infrastructure.service.DeviceUnionpayParamService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service("deviceBffService")
public class DeviceBffServiceImpl implements DeviceBffService {

    @Resource
    private DeviceUnionpayParamService deviceUnionpayParamService;
    @Resource
    private DeviceBizService deviceBizService;

    /**
     * 获取智能终端支付设备信息
     *
     * @param cpu 终端cpu
     * @return
     */
    @Override
    public DeviceUnionpayParamVo getDeviceUnionpayParam(String cpu) {
        return Convert.toDeviceUnionpayParamVo(deviceUnionpayParamService.getDeviceUnionpayParam(cpu));
    }

    /**
     * 通过cpu查询智能终端信息
     *
     * @param cpu
     * @return
     * @throws Exception
     */
    @Override
    public DeviceInfoVo getDeviceInfo(String cpu) throws Exception {
        DeviceInfoBizDto deviceInfoBizDto = deviceBizService.getDeviceInfo(cpu);
        return Convert.toDeviceInfoVo(deviceInfoBizDto);
    }

    /**
     * 终端
     *
     * @param map
     * @return
     */
    @Override
    public DeviceInfoVo getDeviceStatus(Map<String, Object> map) {
        String cpu = ObjectCastUtil.castString(map.get("cpu"));
        if (StringUtils.isBlank(cpu)) {
            throw new BizException("cpu号不能为空");
        }
        DeviceInfoBizDto deviceInfoBizDto = deviceBizService.getDeviceStatus(map);
        return Convert.toDeviceInfoVo(deviceInfoBizDto);
    }

}
